#ifndef TESTER_EXAMPLE_MATRIX_H_
#define TESTER_EXAMPLE_MATRIX_H_

#include <cstring>
#include <stdexcept>


template<class T>
class Matrix {
   private:
      size_t _rows;
      size_t _cols;

      T *matrix;

      Matrix(const Matrix &aCopiar);
      Matrix& operator=(const Matrix &aCopiar);

   public:
      class Row {
         private:
            friend class Matrix<T>;

            T *row;
            size_t _cols;
            Row(T *row, size_t cols) : row(row), _cols(cols) {}

         public:
            T& operator[](size_t col) {
               if(col >= _cols) throw std::out_of_range("Number of columns exceeded.");
               return row[col];
            }
      };


      Matrix(size_t rows, size_t cols) : 
         _rows(rows), 
         _cols(cols), 
         matrix(new T[rows*cols]) {}

      Row operator[](size_t row) {
         if(row >= _rows) throw std::out_of_range("Number of rows exceeded.");
         return Row(&matrix[row * _cols], _cols);
      }

      ~Matrix() throw() {
         if(matrix) delete[] matrix;
      }

      size_t rows() const { return _rows; }
      size_t cols() const { return _cols; }
};

#endif
